package cn.uil.demo;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Aspect
@Component
public class PostConstructAspect {

    @Around("@annotation(javax.annotation.PostConstruct) && execution(* *(..))")
    public Object wrapPostConstruct(ProceedingJoinPoint pjp) throws Throwable {
        // 将标准 @PostConstruct 转为异步执行
        Method method = ((MethodSignature) pjp.getSignature()).getMethod();
        if (!method.isAnnotationPresent(AsyncPostConstruct.class)) {
            throw new IllegalStateException("Standard @PostConstruct not allowed");
        }
        return pjp.proceed(); // 实际由AsyncPostConstructProcessor处理
    }
}
